# -*- coding: utf-8 -*
from django.contrib.auth.models import User, Group
from django.utils.translation import ugettext_lazy as _
from django.db import models
from mysitebbs import settings as forum_settings
import time
# Create your models here.

class ForumModel(models.Model):
	#论坛id
	#forum = models.AutoField(max_length=8,primary_key=True)
	#上级论坛id
	fup = models.ForeignKey("self",related_name='father')
	#论坛名称
	name = models.CharField(max_length=50)
	#显示状态(0:隐藏 1:正常 3:群组)'
	status = models.SmallIntegerField(max_length=1,default=1)
	#类型 0:分类 1:普通论坛 2:子论坛
	type = models.SmallIntegerField(max_length=1,default=1)
	#主题数量
	threads = models.IntegerField(max_length=8,default=0)
	#帖子数量
	posts = models.IntegerField(max_length=8,default=0)
	#今日发帖数量
	todayposts = models.IntegerField(max_length=8,default=0)
	#最后发表
	lastpost = models.CharField(max_length=110,blank=True)
	
class TopicModel(models.Model):	
	#主题id 
	#topic = models.AutoField(max_length=8,primary_key=True)
	#论坛id
	forum = models.ForeignKey(ForumModel,related_name='topics')
	#发表人id
	author = models.ForeignKey(User,related_name='author')
	#发表人
	author_name = models.CharField(max_length=80)
	#标题
	subject = models.CharField(max_length=80,blank=False)
	#发表时间
	dateline = models.DateTimeField(auto_now_add=True)
	#最后发表人
	lastposter = models.ForeignKey(User,related_name='lastposter')
	#最后发表时间
	lastpost_time = models.DateTimeField(auto_now=True)
	#浏览次数
	views = models.IntegerField(max_length=10,default=0)
	#回复次数
	replies = models.IntegerField(max_length=8,default=0)
	#帖子数
	post_count = models.IntegerField(blank=True, default=0)
	
	#是否置顶
	#stickreply 
	#是否精华
	#digest
	#是否高亮 
	#highlight 
	#是否评分
	#rate
	#
	#subjectcolor
	
	def __getattr__(self,name):
		if name == "createtime":
			return time.strftime("%m-%d %R", self.dateline.timetuple())
		if name == "updatetime":
			return time.strftime("%m-%d %R", self.lastpost_time.timetuple())
		return ""

class PostModel(models.Model):
	#帖子id
	#post = models.AutoField(max_length=10,primary_key=True)
	#所属主题
	topic = models.ForeignKey(TopicModel,related_name='posts',verbose_name=_('Topic'))
	#
	first = models.SmallIntegerField(max_length=1,default=0)
	# 
	author = models.ForeignKey(User,related_name='posts',verbose_name=_('User'))
	#
	author_name = models.CharField(max_length=255)
	#
	authorip = models.IPAddressField(blank=True)
	#
	dateline = models.DateTimeField(auto_now_add=True)
	#
	message = models.TextField()
	#
	invisible = models.SmallIntegerField(max_length=1,default=0)
	#
	anonymous = models.SmallIntegerField(max_length=1,default=0)
	#
	tags = models.CharField(max_length=200,blank=True)
	#
	position = models.IntegerField(max_length=8,default=0)
	
	def __getattr__(self,name):
		if name == "createtime":
			return time.strftime("%m-%d %R", self.dateline.timetuple())
		return ""

RECOMMENDTYPE = (('','精华'),('','推荐'),('','置顶'),('',''))